# Contributor: TBK <alpine@jjtc.eu>
# Maintainer: TBK <alpine@jjtc.eu>
pkgname=nebula
pkgver=1.8.2
pkgrel=1
pkgdesc="Scalable overlay networking tool with a focus on performance, simplicity and security"
url="https://github.com/slackhq/nebula"
license="MIT"
# tests seem to fail due to >32-bit allocs, probably doesn't work
# s390x: service_test timed out
arch="all !x86 !armhf !armv7 !s390x"
pkgusers="$pkgname"
pkggroups="$pkgname"
install="$pkgname.pre-install"
makedepends="go"
subpackages="$pkgname-openrc"
source="https://github.com/slackhq/nebula/archive/v$pkgver/nebula-$pkgver.tar.gz
	unset-CGO_ENABLED.patch
	fix-gvisor.patch
	$pkgname.initd
	"

# secfixes:
#   1.8.1-r0:
#     - CVE-2023-48795

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make BUILD_ARGS="$GOFLAGS" BUILD_NUMBER="$pkgver" bin
}

check() {
	make test
}

package() {
	install -Dm750 -o nebula -g nebula nebula -t "$pkgdir"/usr/sbin/

	install -Dm755 nebula-cert -t "$pkgdir"/usr/bin/

	install -Dm644 examples/config.yml -t "$pkgdir"/etc/$pkgname

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
}

sha512sums="
48c89b33982cf4ed4b674890ef3f925b54f3a1221f4869a92d940674672f6c32f1e58a12d3b19190568fb5b7b848a46345c16d53a7ac55f8e2cf4a0fd474b3c3  nebula-1.8.2.tar.gz
d42c1ab0c2fd3db5911694f01fe709527112867fb0c8736ddce5b1ff9787860d33100379d11b02d5ff69b99ca183655a6a489b8d79d21a347737d1398d5ad3ce  unset-CGO_ENABLED.patch
c930e3463a2901c0ea4c848cd1d090ba5c28248e8abbb2bcd147ab78f2317f77cc313fc74edfea0282a7ec80fe4ba9eac1ec6af36c43e8bacba8bc0ea547aa32  fix-gvisor.patch
b86a38a0e558f2bc00b062d713cd3ad3e6b5e7a0695c92d7bfe5633edb80184fcd64ebf5af6c35677c91719159dad8cd38c2278b5f4d9f5d2e42f101e6e354b2  nebula.initd
"
